package com.thresh.blog.controller;

import com.thresh.blog.pojo.Blog;
import com.thresh.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class BlogController {
    @Autowired
    private BlogService blogService;

    @RequestMapping("/getBlogs")
    public String toBlogList(Model model, @Param("page") int page, @Param("size") int size){
        Pageable pageRequest = PageRequest.of(page, size);
        Page<Blog> blogs = blogService.getBlogs(pageRequest);
        model.addAttribute("blogs",blogs);
        return "client/index";
    }
}
